<?php
/**
 *	Поле Код
 */
function get_field_code ($field_value,$action,$field_id=0,$tpl='',$tpl_empty=0,&$maxlength = '',$doc_fields=array(),$rubric_id=0,$dropdown='')
{
	switch ($action)
	{
		case 'edit':
			global $AVE_Template;
			$AVE_Template->assign('field_id', $field_id);
			$AVE_Template->assign('field_value', $field_value);
			return $AVE_Template->fetch(BASE_DIR . '/fields/code/code.tpl');

		case 'js':
			return array(
				'admin/codemirror/lib/codemirror.js',
				'admin/codemirror/mode/xml/xml.js',
				'admin/codemirror/mode/javascript/javascript.js',
				'admin/codemirror/mode/css/css.js',
				'admin/codemirror/mode/clike/clike.js',
				'admin/codemirror/mode/php/php.js',
				'admin/codemirror/addon/hint/show-hint.js',
				'admin/codemirror/addon/edit/closetag.js',
				'admin/codemirror/addon/hint/html-hint.js',
				'admin/codemirror/addon/selection/active-line.js',
				'admin/codemirror/addon/dialog/dialog.js',
				'admin/codemirror/addon/search/searchcursor.js',
				'admin/codemirror/addon/search/search.js',
				'admin/codemirror/functions.common.js',
				'fields/code/code.js'
			);

		case 'css':
			return array(
				'admin/codemirror/lib/codemirror.css',
				'admin/codemirror/addon/hint/show-hint.css',
				'admin/codemirror/addon/dialog/dialog.css',
			);

		case 'doc':
		case 'req':
			return get_field_default($field_value,$action,$field_id,$tpl,$tpl_empty);

		case 'update':
			global $AVE_DB;
			$AVE_DB->Query("
				UPDATE " . PREFIX . "_document_fields
				SET field_value = '" . $_POST['feld'][(int)$_REQUEST['field_id']] . "'
				WHERE
					document_id = '" . (int)$_REQUEST['doc_id'] . "' AND
					rubric_field_id = '" . (int)$_REQUEST['field_id'] . "'
			");
			exit;

		case 'name':
			return 'FIELD_CODE';

		default: return $field_value;
	}
}
?>